<%@ page import="com.biz.conf.Global" %>
<%@ page import="com.biz.model.Singleton.ZkNode" %>
<%@ page import="com.framework.utils.ConfigUtil" %>
<%@ include file="/jsp/taglib.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <%--<link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/jsTree/style.min.css" rel="stylesheet">

<style>
    .fileInputContainer{
        width: 150px;
        background-size: 100% 100%;
        height: 150px;
        background-repeat: no-repeat;
    }
    .fileInput{
        position: absolute;
        top:30%;
        left:30%;
    }.upload_pic {
         height: 70px;
         width:70px;
         position: relative;
         cursor: pointer;
         color: #ccbe9e;
         background: #fff;
         overflow: hidden;
         display: inline-block;
         *display: inline;
         *zoom: 1;
     }
    .upload_pic input {
        position: absolute;
        height:100%;
        width:100%;
        right: 0;
        top: 0;
        opacity: 0;
        filter: alpha(opacity=0);
        cursor: pointer
    }
    .upload_pic:hover {
        color: #ccbe9e;
        background: #fff;
        text-decoration: none
    }
</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>表单验证</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm" onsubmit="return  false">
                        <input type="hidden" value="${page_type}" name="pslide.page_type">
                        <input type="hidden" value="${id}" name="pslide.id">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片：</label>
                            <div class="col-sm-8">
                                <%--<div class="fileInputContainer" id="f03" align="center">--%>
                                <input type="hidden" id="picid2" name="pslide.path">
                                <div class="dtupload">
                                    <a href="javascript:;" class="upload_pic" style="height:80px;"><input type="file" name="fileToUpload" id="upfile2" onChange="uploadFileEidt('upfile2','f03');">
                                        <img  id="f03" src="${pageContext.request.contextPath}/resources/image/logopic1.png" width="100%"  height="100%"/>
                                    </a>
                                </div>
                            </div>
                        </div>
                        <%--<div class="form-group">--%>
                            <%--<label class="col-sm-3 control-label">位置：</label>--%>
                            <%--<div class="col-sm-8">--%>
                                <%--<select id="position" data-placeholder="" class="chosen-select"  name="pslide.position" class="form-control" onchange="changePosition(this.value)">--%>
                                    <%--<option value= "0">首页轮播</option>--%>
                                    <%--<option value= "1">首页列表</option>--%>
                                    <%--<option value= "2">个人中心</option>--%>
                                <%--</select>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">类型：</label>
                            <div class="col-sm-8">
                                <select id="type" data-placeholder="" class="chosen-select"     name="pslide.type" class="form-control" onchange="changeType(this.value)">
                                    <option value= "0">图文轮辐</option>
                                    <option value= "1">产品轮辐</option>
                                    <option value= "2">外链轮辐</option>
                                    <option value= "3">富文本轮辐</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否开启：</label>
                            <div class="col-sm-8">
                                <select id="isOpen" data-placeholder="所属仓库..." class="chosen-select"     name="pslide.isOpen" class="form-control">
                                    <option value= "1">是</option>
                                    <option value= "0">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商城类型：</label>
                            <div class="col-sm-8">
                                <select id="goodsType" data-placeholder="所属仓库..." class="chosen-select"     name="pslide.goodsType" class="form-control">
                                    <option value= "0">现金商城</option>
                                    <option value= "1">积分商城</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group"  id="div_goodsId" style="display: none">
                            <label class="col-sm-3 control-label">产品名称：</label>
                            <div class="col-sm-8">
                                <input type="hidden" id="goodsId" name="pslide.goodsId">
                                <input id="goodsName" name="pslide.goodsName" class="form-control" type="text" readonly onclick="showGoodsList()">
                            </div>
                        </div>
                        <div class="form-group" id="div_url" style="display: none">
                            <label class="col-sm-3 control-label">外链地址：</label>
                            <div class="col-sm-8">
                                <input id="url" name="pslide.url" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="col-sm-8">
                                <input id="name" name="pslide.name" class="form-control" type="text">
                            </div>
                        </div>
                        <%--<div class="form-group">--%>
                            <%--<label class="col-sm-3 control-label">价格：</label>--%>
                            <%--<div class="col-sm-8">--%>
                                <%--<input id="price" name="pslide.price" class="form-control" type="text">--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序：</label>
                            <div class="col-sm-8">
                                <input id="sort" name="pslide.sort" class="form-control" type="text" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">内容：</label>
                            <div class=" col-sm-9">
                                <!-- 加载编辑器的容器 -->
                                <script id="container" name="content" style="height:300px" type="text/plain">
                                </script>
                                <input id="notes" name="pslide.notes" type="hidden">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary"  onclick="doSave()">提交</button>
                                <button id="btn_close"  class="btn btn-primary" type="button">关闭</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/demo/form-validate-demo.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/layer2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/ajaxfileupload.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.all.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script>
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
var picPath='<%=Global.getConfig("OSSURL")%>';
    <!-- 实例化编辑器 -->
    var ue = UE.getEditor('container');
    <!-- 自定义上传图片-->
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadfile') {
            return '${ctx}/ue/uploadImageForUE.ac';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    };
    var id='${id}';
    //对编辑器的操作最好在编辑器ready之后再做
    ue.ready(function() {
        //设置编辑器的内容
        ue.setContent('');
        //获取html内容，返回: <p>hello</p>
        var html = ue.getContent();
        //获取纯文本内容，返回: hello
        var txt = ue.getContentTxt();

        if(id!=null&&id!=''&&id!=undefined)//如果是编辑，读取数据
        {
            loadForEdit(id);
        }else{
            initializeSelect();
        }
        <%--var page_type='${page_type}';--%>
        <%--if(page_type=='update'){--%>
            <%--ue.setContent('${twxgoods.info}');--%>
        <%--}--%>
    });
    
    $(function () {
        //初始化下拉框


    })
    
function initializeSelect() {
    $("#type").chosen({
        no_results_text : "未找到此选项!",
        width:"100%"
    });
    $("#type").val(0);
    $("#type").trigger("chosen:updated");
//    $("#position").chosen({
//        no_results_text : "未找到此选项!",
//        width:"100%"
//    });
//    $("#position").val(0);
//    $("#position").trigger("chosen:updated");
    $("#isOpen").chosen({
        no_results_text : "未找到此选项!",
        width:"100%"
    });
    $("#isOpen").val(1);
    $("#isOpen").trigger("chosen:updated");

    $("#goodsType").chosen({
        no_results_text : "未找到此选项!",
        width:"100%"
    });
    $("#goodsType").val(0);
    $("#goodsType").trigger("chosen:updated");
}

//选择类型
function changeType(v) {
    $("#goodsId").val("");
    $("#goodsName").val("");
    $("#url").val("");
    if(v==0){
    $("#div_goodsId").hide();
    $("#div_url").hide();
    }else if(v==1){
        $("#div_goodsId").show();
        $("#div_url").hide();
    }else if(v==2){
        $("#div_goodsId").hide();
        $("#div_url").show();
    }else{
        $("#div_goodsId").hide();
        $("#div_url").hide();
    }
}

//加载商品列表
function showGoodsList() {
    layer.open({
        type: 2,
        shift:4,//动画类型
        moveType:1,
        maxmin: true,
        shadeClose: true, //开启遮罩关闭
        area: ['800px', '500px'],
        title:'商品',
        content: '${pageContext.request.contextPath}/pic/toGoodsList.ac',
        success: function(layero, index){
            var datas={"firstname":"555555"};
        },
        cancel: function(index){
            return true;
        }
    });
}



    //parent.layer.iframeAuto(index);
    //让层自适应iframe
    $('#add').on('click', function(){
        $('body').append('插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。');

    });
    //给父页面传值
    $('#transmit').on('click', function(){

       // parent(".J_iframe").$("#spancc").text("5");
        alert(parent.$('#spancc').text());
        $(parent.window.frames["iframe8"].document).find("#spancc").html("我被改变了");
        $(parent.window.frames["iframe8"].document).find("#exampleTablePagination").bootstrapTable('refresh');
        //parent.$('#spancc').html('我被改变了');
        parent.layer.close(index);
    });

    //关闭iframe
    $('#btn_close').click(function(){
        parent.layer.close(index);
    });

    //上传头像
    function uploadFileEidt(obj,pic){
        $.ajaxFileUpload  ({
            url: '${pageContext.request.contextPath}/file/doUploadFile.ac',
            secureuri: false,
            fileElementId: obj,
            dataType: 'json',
            beforeSend: function() {
                //$("#loading").show();
            },
            complete: function() {
                //$("#loading").hide();
            },
            success: function(data, status) {

                var hi=picPath+data.path;
                $("#"+pic).attr("src",hi);
                $("#picid2").attr("value",data.path);
            },
            error: function(data, status, e) {
                alert(e);
            }
        });
    }

    //保存
    function doSave(){
        var path=$("#picid2").val();
        var type=$("#type").val();
        var goodsId=$("#goodsId").val();
        var url=$("#url").val();
        var name=$("#name").val();
//        var price=$("#price").val();
        var sort=$("#sort").val();
        var container=ue.getContent();//编辑框内容
        $("#notes").val(container);

    var flag=true;
    if(path==null||path==undefined||path==''){alert("请上传图片");flag= false;return}
    if((goodsId==null||goodsId==undefined||goodsId=='')&&(type=="1")){alert("请选择商品");flag= false;return}
    if((url==null||url==undefined||url=='')&&(type=="2")){alert("请填写外链地址");flag= false;return}
    if(name==null||name==undefined||name==''){alert("请填写标题");flag= false;return}
//    if(price==null||price==undefined||price==''){alert("请填写价格");flag= false;return}
    if(sort==null||sort==undefined||sort==''){alert("请填写排序");flag= false;return}
        if(flag){
            $.ajax( {
                url:'${pageContext.request.contextPath}/pic/doSave.ac',// 跳转到 action
                data:$("#signupForm").serialize(),
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    if(data=="保存成功")
                    {
                        alert("操作成功！");
                        parent.layer.close(index);
//                        window.top.reload();
                    }else
                    {
                        alert(data);
                    }
                },
                error : function() {
                    alert("操作失败！");
                }
            });
        }
    }

    function loadForEdit(id){
        $.ajax( {
            url:'${pageContext.request.contextPath}/pic/toGetEdit.ac?id='+id,// 跳转到 action
            data:{},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                $("#picid2").val(data.path);
                var hi=picPath+data.path;
                $("#f03").attr("src",hi);
//                $("#position").val(data.position);
                $("#type").val(data.type);
                $("#name").val(data.name);
                $("#goodsId").val(data.goodsId);
                $("#sort").val(data.sort);
                $("#goodsName").val(data.goodsName);
                $("#url").val(data.url);
//                $("#price").val(data.price);
                $("#isOpen").val(data.isOpen);
                $("#goodsType").val(data.goodsType);
                ue.setContent(data.notes);
                var v=data.type;
                if(v=='0'){
                    $("#div_goodsId").hide();
                    $("#div_url").hide();
                }else if(v=='1'){
                    $("#div_goodsId").show();
                    $("#div_url").hide();
                }else if(v=='2'){
                    $("#div_goodsId").hide();
                    $("#div_url").show();
                }else{
                    $("#div_goodsId").hide();
                    $("#div_url").hide();
                }
                $("#type").chosen({
                    no_results_text : "未找到此选项!",
                    width:"100%"
                });
                $("#type").trigger("chosen:updated");
                $("#isOpen").chosen({
                    no_results_text : "未找到此选项!",
                    width:"100%"
                });
                $("#isOpen").trigger("chosen:updated");

                $("#goodsType").chosen({
                    no_results_text : "未找到此选项!",
                    width:"100%"
                });
                $("#goodsType").trigger("chosen:updated");

            },
        });
    }


    //保存商品信息
    function saveGood(goodsId,name) {
        $("#goodsId").val(goodsId);
        $("#goodsName").val(name);
    }

</script>

</body>

</html>

